﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyBanHang.Lib;

namespace QuanLyBanHang.GUI
{
    public partial class frmQLHoaDon : Form
    {
        public frmQLHoaDon()
        {
            InitializeComponent();
        }

        private DataTable _dtbQLHoaDon = KetNoi.GetTable("select tblHoaDon.MaHD,tblKhachHang.TenKH,tblNhanVien.HoTen,tblHoaDon.LoaiHD,tblHoaDon.NgayLap,tblHoaDon.GhiChu FROM (tblHoaDon INNER JOIN tblKhachHang ON tblHoaDon.MaKH=tblKhachHang.MaKH)INNER JOIN tblNhanVien ON tblHoaDon.MaNhanVien=tblNhanVien.MaNhanVien");
        public int i=0;

        private void frmQLHoaDon_Load(object sender, EventArgs e)
        {
            LoaddtgHoaDon();
        }

        public void LoaddtgHoaDon()
        {
            //string sql = "select tblHoaDon.MaHD,tblKhachHang.TenKH,tblNhanVien.HoTen,tblHoaDon.LoaiHD,tblHoaDon.NgayLap,tblHoaDon.GhiChu FROM (tblHoaDon INNER JOIN tblKhachHang ON tblHoaDon.MaKH=tblKhachHang.MaKH)INNER JOIN tblNhanVien ON tblHoaDon.MaNhanVien=tblNhanVien.MaNhanVien";
            dtgHoaDon.DataSource = KetNoi.GetTable("select tblHoaDon.MaHD,tblKhachHang.TenKH,tblNhanVien.HoTen,(case when tblHoaDon.LoaiHD ='1' then N'Nhập' else N'Xuất' end ) as LoaiHD,tblHoaDon.NgayLap,tblHoaDon.GhiChu FROM (tblHoaDon INNER JOIN tblKhachHang ON tblHoaDon.MaKH=tblKhachHang.MaKH)INNER JOIN tblNhanVien ON tblHoaDon.MaNhanVien=tblNhanVien.MaNhanVien");
            dtgHoaDon.AllowUserToAddRows = false;
            dtgHoaDon.AllowUserToDeleteRows = false;
            dtgHoaDon.Columns["MaHD"].HeaderText = "Mã Hợp Đồng";
            dtgHoaDon.Columns["TenKH"].HeaderText = "Tên Khách Hàng";
            dtgHoaDon.Columns["HoTen"].HeaderText = "Người Lập Hóa Đơn";
            dtgHoaDon.Columns["LoaiHD"].HeaderText = "Loại Hóa Đơn";
            dtgHoaDon.Columns["NgayLap"].HeaderText = "Ngày Lập Hóa Đơn";
            dtgHoaDon.Columns["GhiChu"].HeaderText = "Ghi Chú";
        }

        private void dtgHoaDon_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            i = e.RowIndex;
            if (i > 0)
            {
                txtMaHoaDon.Text = dtgHoaDon.Rows[i].Cells[0].Value.ToString();
                comTenKH.Text = dtgHoaDon.Rows[i].Cells[1].Value.ToString();
                comTenNV.Text = dtgHoaDon.Rows[i].Cells[2].Value.ToString();
                comLoaiHD.Text = dtgHoaDon.Rows[i].Cells[3].Value.ToString();
                dtpNgayLap.Text = dtgHoaDon.Rows[i].Cells[4].Value.ToString();
                txtGhiChu.Text = dtgHoaDon.Rows[i].Cells[5].Value.ToString();
            }
        }
    

    }
}
